<?php

/**
 * UserIdentity represents the data needed to identity a user.
 * It contains the authentication method that checks if the provided
 * data can identity the user.
 */
class UserIdentity extends CUserIdentity
{
	#用户ID
	protected $ID ;
	/**
	 * @todo 验证用户登陆
	 * @see CUserIdentity::authenticate()
	 */
	public function authenticate()
	{
		$db = Yii::app()->db;
		$sql = 'SELECT ID,PassWord FROM {{user}} WHERE UserName = :USERNAME AND Flag = 1';
		$comm = $db->createCommand( $sql );
		$comm->bindParam( ':USERNAME' , $this->username );
		$rs = $comm->queryRow();
		if ( ! $rs )
			$this->errorCode='找不到此用户!';
		elseif ( $rs['PassWord'] != md5( $this->password ) )
			 $this->errorCode='用户密码不正确!';
		else{
			$this->errorCode=self::ERROR_NONE;
			$this->ID = $rs['ID'];
		}
		return !$this->errorCode;
	}
	
}